﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Specialized;


namespace MTA.TripPlanner
{
    public class Carrier : BaseFeed<Carrier>
    {
        private String _name = String.Empty;
        private String _code = String.Empty;

        public string Name { get { return _name; } }
        public string Code { get { return _code; } }

        public static string FeedUrl
        {
            get { return ConfigurationManager.AppSettings["CarrierPage"]; }
        }

        public static List<Carrier> GetAll()
        {
            JSONRequest request = new JSONRequest(FeedUrl);
            return ConvertJSONArray(request, o => o["carriers"]["item"], CreateOne, true);
        }

        public static Carrier CreateOne(JObject c) {
            return new Carrier() { _id = int.Parse((string)c["id"]), 
                _name = (String)c["text"], 
                _code = (String)c["code"] };
        }


        public static Carrier GetById(int id)
        {
            throw new NotSupportedException();
            //JSONRequest request = new JSONRequest(FeedUrl);
            //request.Params["id"] = id.ToString();
            //JObject carrier = request.MakeRequest();
            //return CreateOne(carrier);
        }


    }
}
